import 'package:fate_blind_box/chat_view/ahu_text.dart';
import 'package:fate_blind_box/config/app_style.dart';
import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/utils/default/widget_extension_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:qr_flutter/qr_flutter.dart';

import 'logic.dart';

class MemberCodePage extends GetView<MemberCodeLogic> {
  const MemberCodePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Container(
            decoration: BoxDecoration(
                gradient: LinearGradient(
              colors: ['#197159F5'.stringToColor, '#FFFFFF'.stringToColor],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            )),
          ),
          SingleChildScrollView(
            child: Column(
              children: [
                SizedBox(
                  height: ScreenUtil().statusBarHeight,
                ),
                SizedBox(
                  height: 41.w,
                ),
                Container(
                  width: 315.w,
                  height: 426.w,
                  color: Colors.red,
                  child: RepaintBoundary(
                    key: controller.state.printKey,
                    child: Stack(
                      children: [
                        Image.asset(
                          'images/ic_invite2.png',
                          width: 315.w,
                          height: 426.w,
                          fit: BoxFit.fill,
                        ),
                        Align(
                          alignment: Alignment.bottomCenter,
                          child: Container(
                            width: 140.w,
                            height: 140.w,
                            margin: EdgeInsets.only(
                              bottom: 66.w,
                            ),
                            color: Colors.white,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  height: 7.w,
                                ),
                                Obx(() {
                                  return Text(
                                    '都肆商圈ID:${controller.state.profileNo.value}',
                                    style: const TextStyle(
                                        fontSize: 11, color: Color(0xFF401C66)),
                                  );
                                }),
                                SizedBox(
                                  height: 5.w,
                                ),
                                QrImageView(
                                  padding: EdgeInsets.all(2.w),
                                  backgroundColor: Colors.white,
                                  data: '_getQrInfo()',
                                  version: QrVersions.auto,
                                  size: 102.w,
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 40.w, bottom: 11.w),
                  padding: const EdgeInsets.symmetric(vertical: 10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      InkWell(
                        onTap: () {
                          controller.onClick('wechat');
                        },
                        child: _buildIconText("images/ic_wechatfriend.png", ""),
                      ),
                      SizedBox(
                        width: 60.w,
                      ),
                      InkWell(
                        onTap: () {
                          controller.onClick('circle');
                        },
                        child: _buildIconText("images/ic_friendCicle.png", ""),
                      ),
                    ],
                  ),
                ),
                Container(
                  alignment: Alignment.center,
                  margin: const EdgeInsets.fromLTRB(10, 10, 10, 0),
                  padding: const EdgeInsets.symmetric(vertical: 10),
                  height: 45.w,
                  width: 249.w,
                  decoration: ShapeDecoration(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(22.5)),
                    color: const Color(0xFF7F69D9),
                  ),
                  child: const Text(
                    '点击保存到相册',
                    style: TextStyle(color: Colors.white, fontSize: 16),
                  ),
                ).clickAction(tapAction: () => controller.saveLocImage()),
                Container(
                  width: double.infinity,
                  margin: const EdgeInsets.only(top: 5),
                  color: Colors.transparent,
                  child: AhuText(
                    text: '邀请好友增加20次机会',
                    color: ThemeColor.textColorSecond,
                    fontSize: 14,
                    textAlign: TextAlign.center,
                    fontWeight: FontWeight.w400,
                  ),
                ),
                SizedBox(height: 120.w),
              ],
            ),
          ),
          Positioned(
            left: 0,
            right: 0,
            top: 0,
            height: kToolbarHeight,
            child: Container(
              color: Colors.transparent,
              alignment: Alignment.bottomCenter,
              child: Stack(
                children: [
                  const Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      AhuText(
                        text: '员工码',
                        fontSize: 18,
                        fontWeight: FontWeight.w600,
                        textAlign: TextAlign.center,
                      ),
                    ],
                  ),
                  Positioned(
                    left: 0,
                    bottom: 0,
                    width: 44.w,
                    height: 30.w,
                    child: IconButton(
                        onPressed: () {
                          Navigator.of(context).pop();
                        },
                        icon: Icon(
                          Icons.arrow_back_ios,
                          color: '#333333'.stringToColor,
                          size: 24.w,
                        )),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildIconText(String icon, String text) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Image.asset(icon, width: 45, height: 70),
      ],
    );
  }
}
